package dead.queue.at.demo.message;


import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import dead.queue.at.demo.entity.MessageInfo;
import dead.queue.at.demo.entity.MessageNameConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

@Component
public class MessageReceiver {

    @Autowired
    RedisTemplate  redisTemplate;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * at队列消费
     * @param message
     * @param channel
     * @throws IOException
     */
    @RabbitListener(queues = MessageNameConfig.testQueueName, concurrency = "1")
    public void receiveMessage(Message message, Channel channel) {

        System.out.println("at接收到消息");

        //触发异常
        int[] arrays = {1};
        int aa = arrays[10];

    }

    /**
     * 死信队列消费方法
     * @param message
     * @param channel
     * @throws IOException
     */
    @RabbitListener(queues = MessageNameConfig.testDeadLetterQueueName)
    public void process(Message message, Channel channel) throws IOException {
        System.out.println("at收到进入死信队列消息");

        //触发钉钉告警
        System.out.println("触发钉钉死信告警");

        //写入死信消息写入数据库
        System.out.println("死信数据写入数据库");

    }


}
